/**
 * 
 */
package labox.innovation.gameserver.model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.gameserver.timer.Timer;

/**
 * @author ljsh 寄售的物品
 */
public class ConsignmentItem {
	private static Logger _log=LoggerFactory.getLogger(ConsignmentItem.class);
	private Timer timer;

	/**
	 * 寄售物品的Id
	 */
	private long _itemId;

	/**
	 * 上架时间
	 */
	private long shelveTime;

	/**
	 * 寄售时长
	 */
	private long consignmentLength;

	/**
	 * 物品价格
	 */
	private int _price;

	/**
	 * 是否上架true
	 */
	private boolean isShelve;

	/**
	 * 价格类型
	 */
	private int _priceType;

	/**
	 * 上架的物品
	 */
	private L2ItemInstance _item;

	/**
	 * @param item
	 * @param consignmentLength
	 * @param price
	 * @param priceType
	 * @param isshelve 创建寄售物品对象，当isshelve为true时，将该对象添加到全局上架列表
	 */
	public ConsignmentItem(L2ItemInstance item, long consignmentLength, int price, int priceType, boolean isshelve) {
		if (item == null || consignmentLength == 0) {
			return;
		}

		shelveTime = System.currentTimeMillis();
		_itemId = item.getObjectId();
		_item = item;
		_price = price;
		this.consignmentLength = consignmentLength;
		isShelve = isshelve;
		_priceType = priceType;
	}

	/**
	 * @param item
	 * @param consignmentLength
	 * @param price
	 * @param priceType
	 * @param isshelve
	 * @param mark 描述 从数据库加载出来调用该方法
	 */
	public ConsignmentItem(L2ItemInstance item, long consignmentLength, int price, int priceType, boolean isshelve, String mark) {
		this(item, consignmentLength, price, priceType, isshelve);
		FuzeWorld.getInstance().enterWorld(item);
	}

	public Timer getTimer() {
		return timer;
	}

	public void setTimer(Timer timer) {
		this.timer = timer;
	}

	public boolean isShelve() {
		return isShelve;
	}

	public void setShelve(boolean isShelve) {
		this.isShelve = isShelve;
		if (isShelve)
			shelveTime = System.currentTimeMillis();
	}

	public long getShelveTime() {
		return shelveTime;
	}

	public void setShelveTime(long shelveTime) {
		this.shelveTime = shelveTime;
	}

	public L2ItemInstance getItem() {
		return _item;
	}

	public long getConsignmentLength() {
		return consignmentLength;
	}

	public void setConsignmentLength(long consignmentLength) {
		this.consignmentLength = consignmentLength;
	}

	public int getPrice() {
		return _price;
	}

	public void setPrice(int type) {
		_price = type;
	}

	public int getPriceType() {
		return _priceType;
	}

	public void setPriceType(int type) {
		_priceType = type;
	}

	public long getItemId() {
		return _itemId;
	}

	public void setItemId(long itemId) {
		_itemId = itemId;
	}

	/**
	 * @author ljsh 物品下架任务
	 */
	public static class TheShelfTask implements Runnable {
		private ConsignmentItem _item;

		public TheShelfTask(ConsignmentItem item) {
			_item = item;
		}

		@Override
		public void run() {
			try {
				if (_item != null) {
					_item.setShelve(false);
					ConsignmentManager.shelf(_item);
				}
			} catch (Exception e) {
				//_log.error(arg0, arg1, arg2)
			}
		}
	}

}
